home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
COMMUNIC
/
H097.ZIP
/
TM4123.ZIP
/
TMSCRIPT.DOC
< prev
next >
Wrap
Text File
|
1993-07-20
|
159KB
|
4,558 lines
▌███████████ ▌█████████▌ ▌██████ ▌█ ▌█
▌█▌ ▌█▌ ▌█▌ ▌█▌ ▌█▌ ▌█
▌█▌ ▌█▌ ▌█▌ ▌█▌ ▌█▌ ▌████▌ ▌████ ▌█ ▌██████ ▌█████
▌█▌ ▌█▌ ▌█▌ ▌█▌ ▌██████ ▌█ ▌█ ▌█ ▌█ ▌█ ▌█
▌█▌ ▌█▌ ▌█▌ ▌█▌ ▌█ ▌█ ▌█ ▌█ ▌█ ▌█ ▌█
▌█▌ ▌█▌ ▌█▌ ▌█▌ ▌█ ▌█ ▌█ ▌█ ▌█ ▌█ ▌█
▌█▌ ▌█▌ ▌█▌ ▌█▌ ▌██████ ▌████▌ ▌█ ▌█ ▌██████ ▌███
▌█
▌█
▌█
Telemate Script Language
Version 4.12
By Tsung Hu, White River Software
Copyright (c) 1988-1993 White River Software.
All rights reserved.
TELEMATE SCRIPT TABLE OF CONTENTS i
TABLE OF CONTENTS
INTRODUCTION 1
Using TMS.EXE, the Script Compiler . . . . . . . . . . . . . . . . 1
To Run a Script . . . . . . . . . . . . . . . . . . . . . . . . . . 1
What Is Your Name . . . . . . . . . . . . . . . . . . . . . . . . . 2
DATA TYPES 3
Integer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Character . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Boolean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Date . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
VARIABLES 5
Variable Identifiers . . . . . . . . . . . . . . . . . . . . . . . 5
Variable Declarations . . . . . . . . . . . . . . . . . . . . . . . 5
Predefined Variables . . . . . . . . . . . . . . . . . . . . . . . 5
CONNECTED . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
FOUND . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
SUCCESS . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
LOGGING . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
WIDTH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
HEIGHT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
EXPRESSIONS 9
Rule Of Precedence . . . . . . . . . . . . . . . . . . . . . . . . 9
Arithmetic Operators . . . . . . . . . . . . . . . . . . . . . . . 9
Boolean Operators . . . . . . . . . . . . . . . . . . . . . . . . . 9
Relational Operators . . . . . . . . . . . . . . . . . . . . . . . 10
STATEMENTS 11
Comment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Assignment Statement . . . . . . . . . . . . . . . . . . . . . . . 11
If Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Switch Statement . . . . . . . . . . . . . . . . . . . . . . . . . 12
While Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Repeat Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Exit Statement . . . . . . . . . . . . . . . . . . . . . . . . . . 14
#include Directive . . . . . . . . . . . . . . . . . . . . . . . . 15
PROCEDURES 16
Procedure Declaration . . . . . . . . . . . . . . . . . . . . . . . 16
Parameter Declaration . . . . . . . . . . . . . . . . . . . . . . . 17
Calling Procedure and Parameter Passing . . . . . . . . . . . . . . 17
Nested Procedures and Scope of Variables . . . . . . . . . . . . . 18
Return Statement . . . . . . . . . . . . . . . . . . . . . . . . . 19
BUILT IN PROCEDURES BY CATEGORY 20
Console I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Print Statement . . . . . . . . . . . . . . . . . . . . . . . . 20
COM I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Put Statement . . . . . . . . . . . . . . . . . . . . . . . . . 21
Waitfor Statement . . . . . . . . . . . . . . . . . . . . . . . 21
TELEMATE SCRIPT TABLE OF CONTENTS ii
File Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
String Handling . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Miscellaneous Routines . . . . . . . . . . . . . . . . . . . . . . 22
BUILT IN PROCEDURES 23
Alarm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Append . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
At . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Atoi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
ChDir . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Clear COM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Clear Key . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Clear Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Close . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
ComInCount . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
ComOutCount . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Concat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Create . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Date . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Delay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Delete . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Dial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Dos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
ExitTelemate . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
FileExist . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
FileSize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Get . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
GetCh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
HangUp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
InputCh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Itoa . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Keystroke . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Length . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
LoadFon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
LoadKey . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
LoadMac . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
LoadPad . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
LogOff . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
LogOn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
LogPause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
LogResume . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Open . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Print . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Put . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Query . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Read . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
ReadCh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Receive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Rename . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Seek . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Send . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Stop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
TELEMATE SCRIPT TABLE OF CONTENTS iii
StrDel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
StrIns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
StrPos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
StrSet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
SubStr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Tell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Waitfor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
WaitUntil . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
When . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
WhenIdle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
WhereX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
WhereY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Write . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
TOOLBOX PROCEDURES 58
Toolbox #1 59
Color Values and ANSI Color Codes . . . . . . . . . . . . . . . 59
EchoToLocal and EchoToRemote . . . . . . . . . . . . . . . . . . 60
Echo and EchoInt . . . . . . . . . . . . . . . . . . . . . . . . 60
EchoBkColor . . . . . . . . . . . . . . . . . . . . . . . . . . 61
EchoBlink . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
EchoBlock . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
EchoBox . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
EchoClearScreen . . . . . . . . . . . . . . . . . . . . . . . . 63
EchoColor . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
EchoGotoXY . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
EchoHiLite . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
EchoNormal . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
EchoReverse . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Toolbox #2 65
GetN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
InputN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
ReadN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
isalpha . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
isalnum . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
iscntl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
isdigit . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Toolbox #3 68
ConvertDate . . . . . . . . . . . . . . . . . . . . . . . . . . 68
DiffDate . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
DiffTime . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
PhoneDirectory . . . . . . . . . . . . . . . . . . . . . . . . . 70
PhoneFind . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
PhoneRead . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
PhoneSize . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
PhoneWrite . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
APPENDIX A: ERROR MESSAGES 73
Compiler Error Messages . . . . . . . . . . . . . . . . . . . . . . 73
Runtime Error Messages . . . . . . . . . . . . . . . . . . . . . . 75
INDEX 76
TELEMATE SCRIPT INTRODUCTION 1
INTRODUCTION
──────────────────────────────────────────────────────────────────────────
TMScript allows you to write procedures to perform repetitive
functions, such as a log on script, as well as specific applications,
such as the host mode.
TMScript is designed to be a easy-to-use language. TMScript looks
similar to the Pascal language and the syntax is as loose as that of
BASIC language. For most of the users, only the WAITFOR, PUT and maybe
the WHEN statements are necessary. For those users who have experience
in the other programming language, TMScript is a powerful tool for
communication related application.
A script file can be created using almost all editors. The source file
is a normal ASCII text file which contains a sequence of instructions
telling Telemate what to perform next. The source file should use the
extension .SCR to indicate that it is a SCRipt file.
Using TMS.EXE, the Script Compiler
──────────────────────────────────────────────────────────────────────────
Once the source file is written, it must be compiled (translated) to a
form that Telemate can load and interpret quickly. To compile a source
file, type
TMS filename
where <filename> is the filename of the source file. The extension can
be omitted if it is .SCR. TMS.EXE compiles the file 'filename.SCR' and
produces the compiled script file 'filename.TMS'. For example, typing
'TMS \TM\HOST', TMS compiles '\TM\HOST.SCR' and produces
'\TM\HOST.TMS'.
If a syntax error is encountered in the source file, the compiler
reports the line number and the type of the error. You should edit the
source file and recompile until there is no more errors.
To Run a Script
──────────────────────────────────────────────────────────────────────────
There are several ways to run a script.
1. Pressing [Alt S] at the Terminal Window opens the File Dialog and
you are asked to identify which script file to be executed.
2. Put the script name in the link-script field of the phone
directory. When the BBS is connected, the link-script is executed
automatically. Link-scripts are sometimes referred as logon scripts
because they perform repetitive logon procedure.
3. Type 'TM <scriptname>' at the DOS command line. For example,
C>TM HOST
put Telemate in host mode when start.
TELEMATE SCRIPT INTRODUCTION 2
4. You may assign a function key to execute a script file using the
"^\" macro sequence. For example, the function key [Alt 4] is
"^\host", when you press [Alt 4], the host script will be executed.
5. The SCRIPT statement allows you run another script in a script
program. Please refer the description of the SCRIPT statement.
What Is Your Name
──────────────────────────────────────────────────────────────────────────
The first example program is a simple logon script. It waits for the
logon prompts and sends the response to the remote system.
WAITFOR "What is your name?"; wait for the logon prompt
PUT "my name" ; send your name to remote system
WAITFOR "is your password?" ; wait for the password prompt
PUT "my password" ; send your name to remote system
A script can be as simple as that and it will help you to logon to the
remote system automatically.
TELEMATE SCRIPT DATA TYPES 3
DATA TYPES
──────────────────────────────────────────────────────────────────────────
TMScript provides two basic data types, integer and string, and four
extended data types, character, boolean, date and time.
Integer
──────────────────────────────────────────────────────────────────────────
Ordinary number notation is used for integers. Decimal and engineering
notation (e or E followed by an exponent) is not supported. Integer
must within the range from -2147483648 to 2147483647.
String
──────────────────────────────────────────────────────────────────────────
A string is a sequence of zero or more characters from extended ASCII
character set (0-255), enclosed by quotation marks. A string with
nothing in it is called a empty string. Two sequential quotation marks
in a string denote a single character, an quotation mark.
TMScript allows control characters to be embedded in strings. The '^'
character followed by a letter (A-Z, a-z), '@' or '[' denotes a
character of the ASCII code [Ctrl A] to [Ctrl Z], NULL, or ESC
respective.
Here are some examples of strings
"TELEMATE"
"This is a '""'."
"^K^D" ; [Ctrl K] [Ctrl D]
Character
──────────────────────────────────────────────────────────────────────────
Character is represented as a string that contains only one character.
For example, "A" is a character. Control codes are often used in
script programs and are represented as
Code String Description
────── ────── ───────────────
Ctrl-@ "^@" NULL
Ctrl-A "^A"
... ..
Ctrl-H "^H" Backspace
Ctrl-I "^I" TAB
Ctrl-J "^J" LF, line feed
... ..
Ctrl-M "^M" CR, Carriage Return, [Enter]
... ..
Ctrl-Z "^Z"
Ctrl-[ "^[" Escape
TELEMATE SCRIPT DATA TYPES 4
Boolean
──────────────────────────────────────────────────────────────────────────
Boolean (TRUE or FALSE) is represented as a integer. A integer is said
to be TRUE if it is not equal to zero, FALSE if it is equal to zero.
When testing a boolean condition, you should not use the following
code,
IF CONNECTED=1
...
ENDIF
because the variable CONNECTED may have other values. Instead, you
should use
IF CONNECTED
...
ENDIF
to test if CONNECTED is TRUE. And
IF NOT CONNECTED
...
ENDIF
to test if CONNECTED is FALSE.
Date
──────────────────────────────────────────────────────────────────────────
Date is represented as a string with the format "MM-DD-YY". When a
date string is compared with another date string, they are first
converted to the internal format "YYMMDD" so that the comparison
returns the correct result.
Note that the date format option in the main program does not affect
the format in the script. For date conversion, see ConvertDate command
in toolbox #3.
Time
──────────────────────────────────────────────────────────────────────────
Time is also represented as a string but with the format "HH:MM:SS".
When two time strings are being compared, they are converted to the
internal format "HHMMSS" such that the comparison can the correct
result.
TELEMATE SCRIPT VARIABLES 5
VARIABLES
──────────────────────────────────────────────────────────────────────────
Variable Identifiers
──────────────────────────────────────────────────────────────────────────
A variable identifier can contain letters and digits. However, a
variable can only start with a letter. Case is not significant, in the
other word, the variable <notdone> is the same as <NotDone>. A
variable identifier can be of any length, but only the first 8
characters are significant. For examples, the variable identifier
<Number12> is the same as <Number123>.
Variable Declarations
──────────────────────────────────────────────────────────────────────────
A variable declaration embodies a list of identifiers that designate
new variables and their type. For example,
INTEGER lower,upper,step ; integers
STRING message,filename ; strings
INTEGER true,false ; boolean
STRING ch,letter ; character
The variable declaration part should be placed at the beginning of a
script or of a procedure. In TMScript, variables need not declared
before use if no procedure is defined. Therefore, the variable
declaration part can be skipped.
Predefined Variables
──────────────────────────────────────────────────────────────────────────
TMScript built in procedures do not return value. Several predefined
variables are set to the resulting value. They are CONNECTED, FOUND,
SUCCESS, LOGGING, WIDTH and HEIGHT.
CONNECTED
CONNECTED is set to the number of the connected entry (from 1 to
1000). The variable CONNECTED returns to FALSE as soon as the carrier
lost. On the other hand, if the state of the carrier changes from OFF
to ON, CONNECTED is set to TRUE.
IF NOT CONNECTED
PRINT "It is not connected to a remote system."
STOP
ENDIF
SWITCH CONNECTED
CASE 1: PRINT "connected to #1"
CASE 3: PRINT "connected to #3"
CASE 6: PRINT "connected to #6"
ENDSWITCH
TELEMATE SCRIPT VARIABLES 6
The CONNECTED variable is also used in conjunction with the DIAL
statement. If the dialing is successful and connect to a remote
system, the variable is set to the number of the connected entry. If
the DIAL statement aborts without connection, the variable CONNECTED
is set to FALSE, indicating that the DIAL statement is aborted by
operator or the number of attempt exceeds the dial attempt setting.
For example,
DIAL "1 3 6"
IF NOT CONNECTED
PRINT "Dialing process aborted"
STOP
ENDIF
SWITCH connected
CASE 1: PRINT "connected to #1"
CASE 3: PRINT "connected to #3"
CASE 6: PRINT "connected to #6"
ENDSWITCH
Note that this variable reflects the online status only if your modem
reports so. You should check your modem manual to ensure that the
modem CD (carrier detect) signal is reflecting the actual online
status. Most modems use a "&C1" AT command to set it and you should
add it to the modem init string.
FOUND
This variable is set to resulting value after the WAITFOR statement is
executed. It is set to FALSE if time exceeded. Otherwise, it is set to
the string number of the matched string. For example,
WAITFOR "NO CARRIER","thanks for calling","hang up now",100
SWITCH FOUND
CASE 1: PRINT "'NO CARRIER' found"
CASE 2: PRINT "'thanks for calling' found"
CASE 3: PRINT "'hang up now' found"
ENDSWITCH
SUCCESS
This variable is used by several statements. The resulting values and
descriptions is shown in the following table.
Statement Value Description
───────── ───── ──────────────────────────────────────────
Append TRUE the file is successfully opened or created
FALSE cannot create file
ChDir TRUE directory changed
FALSE invalid path
Close TRUE file closed
FALSE cannot close file
TELEMATE SCRIPT VARIABLES 7
Create TRUE the file is successfully created
FALSE cannot create file
Delete TRUE the file is successfully deleted
FALSE cannot delete file
FileSize TRUE the file size is determined successfully
FALSE cannot open file
InputCh ch TRUE a character is read into <ch>
FALSE no character is available
LoadFon TRUE the phone directory is successfully opened
FALSE the phone directory cannot be opened
LoadKey TRUE the keyboard file is successfully opened
FALSE the keyboard file cannot be opened
LoadMac TRUE the macro table is successfully opened
FALSE the macro table cannot be opened
LoadPad TRUE the keypad table is successfully opened
FALSE the keypad table cannot be opened
LogOn TRUE the log file is successfully opened
FALSE the log file cannot be created
Open TRUE the file is successfully opened
FALSE the file does not exist
Read str TRUE a line is read into <str>
FALSE end of file encountered.
ReadCh ch TRUE a character is read into <ch>
FALSE end of file encountered.
Receive TRUE all files are received successfully
FALSE file transfer aborted
Rename TRUE the file is successfully renamed
FALSE cannot rename file
Seek TRUE the file pointer is moved successfully
FALSE disk error
Send TRUE all files are sent successfully
FALSE file transfer aborted
Tell pos TRUE the file pointer is stored in <pos>
FALSE disk error
Write TRUE write successary to file
FALSE cannot write to file
TELEMATE SCRIPT VARIABLES 8
LOGGING
This variable reflects the current file log status and has the values
0 log file close or log file not in use
1 log file open and capturing incoming data
2 log file in pause state
WIDTH
This variable stored the width of the zoomed terminal window which is
equal to the screen width. Possible values are 80 or 132.
HEIGHT
This variable is the height of the zoomed terminal window which is
calculated as
HEIGHT = screen height
if ( menu bar present )
HEIGHT = HEIGHT - 1
if ( status line present )
HEIGHT = HEIGHT - 1
if ( HEIGHT < 24 )
HEIGHT = 24
For example, on EGA 43 line mode with both menu bar and status line
present, HEIGHT is equal to 41. But on 25 line mode, HEIGHT is equal
to 24, not 23, because Telemate's terminal has at least 24 lines
though only 23 lines may be shown on screen. In this case, terminal
will shift up and down to justify the display region.
This variable may alter between two instructions if the users press
[Alt -] to toggle the menu bar and status line. When programming full
screen procedure, you should assume there are 23 lines in the screen
and DO NOT scroll the screen by going to the last line and perform a
line feed.
TELEMATE SCRIPT EXPRESSIONS 9
EXPRESSIONS
──────────────────────────────────────────────────────────────────────────
Rule Of Precedence
──────────────────────────────────────────────────────────────────────────
Expressions are made up of operators and operands. In complex
expressions, rule of precedence clarify the order in which operations
are performed.
Operators Precedence
────────────── ────────────
*,/ first (high)
+,- second
=,<>,<,>,<=,>= third
not fourth
and, or, xor fifth (low)
There are the rules of precedence
1. First, an operand between two operators of difference precedence
is bound to the operator with higher precedence.
2. Second, an operand between two equal operators is bound to the
one on its left.
3. Third, expressions within parentheses are evaluated prior to
being treated as a single operand.
Arithmetic Operators
──────────────────────────────────────────────────────────────────────────
The types of operands for arithmetic operators are shown in the
following table.
Operators Operation Operand Type
───────── ────────────── ────────────
+ addition integer
- subtraction integer
* multiplication integer
/ division integer
For example, the formula to convert Fahrenheit temperature to Celsius
equivalents is
celsius = (fahr-32) * 5 / 9
Boolean Operators
──────────────────────────────────────────────────────────────────────────
The types of operands for arithmetic operators are shown in the
following table.
TELEMATE SCRIPT EXPRESSIONS 10
Operators Operation Operand Type
───────── ─────────── ────────────
not negation boolean
and logical and boolean
or logical or boolean
xor logical xor boolean
Normal Boolean logic governs the results of these operations. For
instance, 'a and b' is TRUE only if both <a> an <b> are TRUE.
Relational Operators
──────────────────────────────────────────────────────────────────────────
The types of operands for arithmetic operators are shown in the
following table. They all have the same precedence.
Operators Operation Operand Types
───────── ──────────── ───────────────────────────
= equal to integer, string, date, time
<> not equal to integer, string, date, time
> greater than integer, string, date, time
>= greater or integer, string, date, time
equal to
< less then integer, string, date, time
<= less then or integer, string, date, time
equal to
When the operands are integer, date or time, the comparison will
produce the usual result such as
Condition Result Operands Type
─────────────────────── ────── ─────────────
1 > 2 FALSE integer
"12-31-89" < "01-01-90" TRUE date
"00:00:00" > "23:59:59" FALSE time
However, if the operands are strings, the operators "<", ">" and "<>"
have another meaning such that you can determine if a string is a sub-
string of another string.
s1 < s2 if s1 is a sub-string of s2
s3 > s4 if s3 is a super-string of s4
s5 <> s6 if s5 is not a sub-string of s6 and
s5 is not a super-string of s6
For example,
Condition Result Explanation
──────────────────── ────── ──────────────────────────────────
"hello" = "Hello" TRUE TMScript is not case sensitive.
"goodbye" < "bye" TRUE "bye" is a sub-string of "goodbye"
"dog" <> "car" TRUE The string is not equal
"abc" >= "xyz" FALSE "abc" is not a super-string of
"xyz" and they are not equal.
TELEMATE SCRIPT STRUCTURED STATEMENTS 11
STATEMENTS
──────────────────────────────────────────────────────────────────────────
Statements describe algorithmic actions that can be executed.
Comment
──────────────────────────────────────────────────────────────────────────
Any characters after ";" are ignored by the TMScript compiler.
Assignment Statement
──────────────────────────────────────────────────────────────────────────
Assignment statements replace the current value of a variable with a
new value specified by an expression. The expression must be
assignment-compatible with the type of the variable.
The program prints the following table of Fahrenheit temperatures and
their centigrade or Celsius equivalents.
0 -17
20 -6
40 4
... ...
280 137
300 148
Here is the program itself.
; Print Fahrenheit-Celsius table
; for f = 0, 20, ... , 300
INTEGER lower,upper,step
INTEGER fahr,celsius
lower = 0 ; lower limit of temperature table
upper = 300 ; upper limit
step = 20 ; step size
fahr = lower ; first item in the table
WHILE fahr <= upper
celsius = (fahr-32) * 5 / 9 ; calcuate the values
PRINT fahr,"^I",celsius ; print the result
fahr = fahr + step ; next item in the table
ENDWHILE
TELEMATE SCRIPT STRUCTURED STATEMENTS 12
If Statement
──────────────────────────────────────────────────────────────────────────
The general form for IF statement is
IF condition
statements
ENDIF
The <statements> is executed only if <condition> is TRUE. Another form
is
IF condition
statements-1
ELSE
statements-2
ENDIF
One and only one of the two statements associated with an <if-else> is
done. If the <condition> is true, <statements-1> is executed; if not,
<statements-2> is executed.
The construction
IF condition-1
statements-1
ELSE
IF condition-2
statements-2
ELSE
IF condition-3
statements-3
ENDIF
ENDIF
ENDIF
occurs so often that it is worth a new keyword ELSEIF. The statement
can be re-written as
IF condition-1
statements-1
ELSEIF condition-2
statements-2
ELSEIF condition-3
statements-3
ENDIF
Switch Statement
──────────────────────────────────────────────────────────────────────────
The SWITCH statement is a special multi-way decision maker that tests
whether an expression matches one of a number of values, an branches
accordingly. The syntax for SWITCH statement is
TELEMATE SCRIPT STRUCTURED STATEMENTS 13
SWITCH expression
CASE value-1:
statements-1
CASE value-2,value-3:
statements-2
OTHERWISE:
statements-3
ENDSWITCH
The SWITCH evaluates the expression and compares its value to all the
cases. Each cases must be labeled by the values of the same type as
the expression. Several values can be separated by comma. If a case
matches the expression value, execution starts at that case and ends
at the next case label. The case labeled OTHERWISE is executed if none
of the other cases is satisfied. A OTHERWISE is optional; if it isn't
there and if none of the cases matches, no action at all takes place.
However, OTHERWISE, if exists, must be placed after all the case
labels.
The program counts digits, blanks, others.
nDigit = 0 ; digit
nBlank = 0 ; blank
nOther = 0 ; others
OPEN "MYFILE" ; open the file "MYFILE"
READCH ch ; read the first character
WHILE success ; if not end of file
SWITCH ch
CASE "0","1","2","3","4","5","7","8","9": ; is digit
nDigit = nDight + 1
CASE " ": ; is blank
nBlank = nBlank + 1
OTHERWISE: ; others
nOther = nOther + 1
ENDSWITCH
READCH ch ; read next character
ENDWHILE
CLOSE ; close the file
PRINT nDigit ; print the results
PRINT nBlank
PRINT nOther
While Loop
──────────────────────────────────────────────────────────────────────────
The WHILE loop is the most general loop. The syntax is
WHILE condition
statements
ENDWHILE
The <condition> is tested. If it is true, the body of the loop (all
the statements before the keyword ENDWHILE is executed. Then the
condition is re-tested, and if true, the body is executed again. When
TELEMATE SCRIPT STRUCTURED STATEMENTS 14
the test becomes false the loop ends, and execution continues at the
statements that follows the loop.
For example, to print the value from 1 to 100, you can write
i = 1 ; start from 1
WHILE i<=100 ; check if it in the range
PRINT i ; print the number
i = i + 1 ; increase the counter by 1
ENDWHILE
Repeat Loop
──────────────────────────────────────────────────────────────────────────
While the WHILE loop test the condition at the top, the REPEAT loop
test it at the bottom. It tests at the bottom after making each pass
through the loop body; the body is always executed at least once.
Consider the loop
REPEAT
statements
UNTIL condition
The statements is executed, then the condition is evaluated. If it is
false, the statements is evaluated again, and so on. If the condition
becomes true, the loop terminates.
For example, to print the value from 1 to 100, you can write
i = 1 ; start from 1
REPEAT
PRINT i ; print the number
i = i + 1 ; increase the counter by 1
UNTIL i>100 ; repeat until it is NOT in the range
Exit Statement
──────────────────────────────────────────────────────────────────────────
It is sometimes convenient to be able to control loop exits other than
by testing at the top or bottom. The EXIT statement provides an early
exit from the loops. A EXIT statement causes the innermost loop to be
exited immediately.
The following program accept strings from keyboard, using a EXIT to
exit from the loop when the string contains an [Esc] ("^[").
REPEAT
INPUT s
IF "^[" <= s ; test if [Esc] is a sub-string of s
EXIT ; before printing it
ENDIF
PRINT s
UNTIL s = "" ; repeat until an empty string is entered
TELEMATE SCRIPT STRUCTURED STATEMENTS 15
#include Directive
──────────────────────────────────────────────────────────────────────────
This compiler directive allows you to write reusable procedures in a
separate file and imports the procedures conveniently. The syntax is
#include "includefile"
The <includefile> will be inserted as if it is physical appear in this
point. The <includefile> must be a pathname with extension. For
example,
#include "TOOLBOX.SCR"
#include "MYLIB.SCR"
inserts the TOOLBOX.SCR and MYLIB.SCR into this point.
The #include directive can be nested as deep as 10 levels.
TELEMATE SCRIPT PROCEDURE 16
PROCEDURE
──────────────────────────────────────────────────────────────────────────
In TMScript, a procedure is equivalent to a subroutine or function in
Fortran, or procedure in Pascal, C etc. A procedure provides a
convenient way to encapsulate some computation in a black box, which
can then be used without worrying about its innards.
For example, to swap the values of two variables, <i> and <j>, you
have to write three lines as follows
temp = i ; put <i> into a temporary variable
i = j ; put <j> into <i>
j = temp ; now put the value of <i> into <j>
Suppose in your script there are a lot of swapping, it will be
convenient to define a procedure called <swap> to perform the
swapping. Then your main program will look like
i = 1
j = 2
swap i,j ; now i=2, j=1
PRINT i ; 2
PRINT j ; 1
This is only a small usage of procedure. Imagine if the procedure is
very complex, you can use it again and again once it is tested and
performs what you need.
Procedure Declaration
──────────────────────────────────────────────────────────────────────────
The syntax of a procedure definition is
PROCEDURE <procname> <parameter declaration>
<local variable declaration>
<statement part>
ENDPROC
<procname> is any valid identifier. <parameter declaration> can be
omitted if the procedure does not required parameters. See next
section for details on parameter declaration.
<local variable declaration> made within a given procedure are visible
only within that procedure. This part should ALWAYS be included in
order to make the program easy to be traced although the declarations
may be omitted.
<statement part> can be considered as a sub-program of the main
program and obeys all the rule described above.
TELEMATE SCRIPT PROCEDURE 17
Parameter Declaration
──────────────────────────────────────────────────────────────────────────
Parameter declaration is similar to variable declaration. For example,
PROCEDURE sample STRING s,t,INTEGER i,j
declares the procedure <sample> with two string parameters <s> and <t>
and two integer parameters <i> and <j>. You may use any combination of
STRING and INTEGER to define parameters. For example,
PROCEDURE sample INTEGER i,STRING p,q,r,s,INTEGER j,k,STRING z
We can write the <swap> procedure as
PROCEDURE swap INTEGER value1,value2 ; swap two integers
INTEGER temp ; declare a local variable
temp = value1 ; store the first value
value1 = value2 ; replace with the second value
value2 = temp ; replace with the first value
ENDPROC
After that, the main program may look like
i = 1
j = 2
k = 3
swap i,j ; now i=2, j=1
swap j,k ; now j=3, k=1
PRINT i,j,k ; 2,3,1
Calling Procedure and Parameter Passing
──────────────────────────────────────────────────────────────────────────
Once the procedure is defined, it can be called by putting the
procedure name in the statement part. In the example, the statements
i = 1
j = 2
swap i,j ; now i=2, j=1
PRINT i,j ; 2,1
call the <swap> procedure with the parameters <i> and <j>.
In the above example, the method used to pass <i> and <j> to the
procedure <swap> is called 'pass by reference' because <i> and <j> can
be changed when return. There is another method called 'pass by value'
of which the parameter cannot be changed.
Consider the following procedure
TELEMATE SCRIPT PROCEDURE 18
PROCEDURE countDown INTEGER num ; print from <num> to 1
WHILE num >= 1 ; check if it is in the range
PRINT num ; print it
num = num-1 ; decrease until num=0
ENDWHILE
ENDPROC
countDown 100 ; pass by value
n = 100
countDown n*2 ; pass by value (200)
PRINT n ; n = 100
countDown (n) ; pass by value (100)
PRINT n ; n = 100
countDown n ; pass by reference
PRINT n ; n = 0 !
If we supply <countDown> with the parameter 100, n*2 or (n), they are
'pass by value'. On the other hand, <n> is 'pass by reference' in the
last statement.
The general rule of method of passing parameters is:
When the parameter is a constant, an expression or surrounded
by parentheses, it is 'pass by value'. Otherwise, it is a
variable and is 'pass by reference'.
The rule applies to string parameter as well. To prevent confusion, we
should rewrite the <countDown> procedure by introducing a local
variable.
PROCEDURE countDown INTEGER num ; print from <num> to 1
INTEGER count ; introduce a local variable
count = num ; if neccessary
WHILE count >= 1 ; check if it is in the range
PRINT count ; print it
count = count-1 ; decrease until 0
ENDWHILE
ENDPROC ; this does not change <num>
Nested Procedures and Scope of Variables
──────────────────────────────────────────────────────────────────────────
TMScript allows nested procedures; you can declare one procedure
inside of another. For example,
PROCEDURE outer
STRING i,j
PROCEDURE inner
INTEGER i
i = 100
PRINT "i = ",i
PRINT "j = ",j
ENDPROC
TELEMATE SCRIPT PROCEDURE 19
i = "This is string 'i'."
j = "This is string 'j'."
inner
PRINT "i = ",i
PRINT "j = ",j
ENDPROC
The <outer> procedure declares two string variables, <i> and <j>.
These two variables can be accessed by both the <outer> procedure and
the <inner> one because they are declared before the <inner>
procedure.
The <inner> procedure declares an integer variable <i>. Although the
two <i>'s share the same name, they are not identical. The inner <i>
is visible in the <inner> procedure but not in the <outer> procedure.
On the other hand, the outer <i> can no longer be accessible in the
<inner> procedure. The statement
i = 100
does not affect the outer <i>. This is called the scope rule.
The output of the program is
i = 100
j = This is string 'j'.
i = This is string 'i'.
j = This is string 'j'.
Return Statement
──────────────────────────────────────────────────────────────────────────
Like the EXIT statement, it is sometimes convenient to be able to
return from a procedure at the middle of the procedure.
The following procedure accept strings from keyboard and print it,
using a RETURN to return from the procedure when the string contains
an [Esc] ("^[").
PROCEDURE acceptString STRING s
INPUT s
IF "^[" <= s ; test if [Esc] is a sub-string of s
RETURN ; before printing it
ENDIF
PRINT s
ENDPROC
TELEMATE SCRIPT BUILT IN PROCEDURES BY CATEGORY 20
BUILT IN PROCEDURES BY CATEGORY
──────────────────────────────────────────────────────────────────────────
Console I/O
──────────────────────────────────────────────────────────────────────────
There are eight statements in the group of console input and output.
Namely,
Input, InputCh, Print, AT, Clear Text, Clear Key, WhereX, WhereY
PRINT Statement
Output is simple, the PRINT statement can print variable or constant
of types integer or string to the terminal window. For example,
PRINT "hello, world"
print the words
hello, world
to the terminal window.
PRINT supplies a newline automatically. However, if a comma ","
follows the string, no newline is supplied. The statement above could
just as well have been written
PRINT "hello, ",
PRINT "world",
PRINT
to produce an identical output. The last PRINT statement supplies a
newline.
PRINT statement accepts more than one argument. Each two arguments are
separated by a comma. For example,
PRINT "x = ",x
PRINT "My name is ",firstName," ",lastName
PRINT
COM I/O
──────────────────────────────────────────────────────────────────────────
As a communication program, TMScript provides thirteen I/O statements
that communicate with the remote system. They are
Get, GetCh, Put, Clear COM, ComInCount, ComOutCount
HangUp, Receive, Send, Waitfor, When, WhenIdle
TELEMATE SCRIPT BUILT IN PROCEDURES BY CATEGORY 21
PUT Statement
COM output is as simple as console output, the PUT statement can send
variable or constant of types integer or string to the remote system.
For example,
PUT "first last"
send the words
first last
and a carriage return [Ctrl M] to the remote system.
PUT supplies a carriage return automatically. However, if a comma ","
follows the string, no carriage return is supplied. The statement
above could just as well have been written
PUT "first ",
PUT "last",
PUT
to produce an identical output. The last PUT statement supplies a
carriage return only.
PUT statement accepts more than one argument. Each two arguments are
separated by a comma. For example,
PUT firstName,";",lastName,";",password
WAITFOR Statement
The WAITFOR statements waits for specified stirngs from the remote
system in a specified time. In TMScript, you can specify more than one
string to wait for. If any of them is received, the FOUND variable is
set to a non-zero value (TRUE). Combined with the PUT statement, you
can tell Telemate when to send a string to the remote system.
Syntax Description
────────────────────────── ─────────────────────────────────
WAITFOR t Set default waiting time
WAITFOR s1,s2, ... , sN Wait until one of the strings is
received
WAITFOR s1,s2, ... , sN, t Wait until one of the strings is
received or waiting time exceeded
For example, the following code segment are usally used in a logon
script program.
WAITFOR "first",30 ; wait for "first" in 30 seconds
IF NOT FOUND
STOP ; stop if prompt not found
ENDIF
PUT "my name" ; send the name
TELEMATE SCRIPT BUILT IN PROCEDURES BY CATEGORY 22
WAITFOR "password",5 ; wait for "password" in 5 seconds
IF NOT FOUND
STOP ; stop if prompt not found
ENDIF
PUT "^&" ; send the password field (^&) in
; in the phone directory
File Handling
──────────────────────────────────────────────────────────────────────────
One text file is allowed to open at a time. The file is open or
created as a read/write file. The file handling procedures are
Open, Created, Append, Read, ReadCh, Write, Seek, Tell, Close,
ChDir, Delete, Rename, FileExist, FileSize
The predefined variable SUCCESS is set to FALSE if there is any error.
String Handling
──────────────────────────────────────────────────────────────────────────
A string is a sequence of character. The limit of the length of a
string is 512 characters. When referring to a character position, the
position is counted from 1. The string handling procedures are
Atoi, Concat, Itoa, Length, StrDel, StrIns, StrPos, StrSet, SubStr
Miscellaneous Routines
──────────────────────────────────────────────────────────────────────────
Alarm, Atoi, Date, Delay, Dial, Dos, ExitTelemate, Image, Itoa,
Keystroke, LoadFon, LoadKey, LoadMac, LoadPad, LogOff, LogOn,
LogPause, LogResume, Query, Script, Set, Time, WaitUntil
TELEMATE SCRIPT BUILT IN PROCEDURES 23
BUILT IN PROCEDURES
──────────────────────────────────────────────────────────────────────────
Alarm
──────────────────────────────────────────────────────────────────────────
Function Pop-up the alarm dialog.
Syntax ALARM
ALARM message
Remarks If the string <message> is specified, it is displayed in
the alarm dialog.
If the message is too long, it can be split to several
lines by putting a "^J" between each line.
Return If the operator press [Enter] or click the OK button in
the alarm dialog, SUCCESS is set to TRUE (non-zero).
If the operator press [Esc] or the alarm time excess,
SUCCESS is set to FALSE (zero).
See also Set AlarmSound, Set AlarmTime
Example
RECEIVE "s"
IF NOT SUCCESS
ALARM "Warning: File transfer aborted"
IF NOT SUCCESS ; if timeout, print message on screen
PRINT "Warning: File transfer aborted"
ENDIF
ENDIF
ALARM "Alarm:^JThis is a^Jvery long message"
Append
──────────────────────────────────────────────────────────────────────────
Function Opens a text file, creates it if necessary, and moves the
file pointer to the end of the file.
Syntax APPEND filename
Remark APPEND opens the text file as a read/write file and strip the
ending EOF [Ctrl Z].
Return Upon successful completion, SUCCESS is set to TRUE. If the
file cannot be created, SUCCESS is set to FALSE.
See also Create, Open
TELEMATE SCRIPT BUILT IN PROCEDURES 24
At
──────────────────────────────────────────────────────────────────────────
Function Positions cursor in terminal window.
Syntax AT column,row
Remark AT moves the cursor to the position within the terminal
window. The upper left corner is (0,0) and the lower right
corner is (79,24) if a 25 rows terminal is used.
See also Print
Atoi
──────────────────────────────────────────────────────────────────────────
Function Converts a string to an integer.
Syntax ATOI s,i
Return <i> contains the converted value or 0 if <s> cannot be
converted to a number.
See also Itoa
ChDir
──────────────────────────────────────────────────────────────────────────
Function Changes current directory.
Syntax CHDIR path
Remark CHDIR causes the directory specified by <path> to become the
current working directory. <path> must specify an existing
directory.
A drive can also be specified in <path> but it changes only
the current directory on that drive; it doesn't change the
active drive.
Return Upon successful completion, SUCCESS is set to TRUE;
otherwise, SUCCESS is FALSE.
See also Delete, FileExist, Rename
Clear COM
──────────────────────────────────────────────────────────────────────────
Function Clears the COM buffer.
Syntax CLEAR COM
TELEMATE SCRIPT BUILT IN PROCEDURES 25
Remark Data being sent and received are placed in a COM buffer,
sometimes it is necessary to clear the buffer before
processing.
See also Get, GetCh, Put
Example
GET s ; get a string
DELAY 50 ; wait for 5 seconds
CLEAR COM ; clear the received data in the last 5 seconds
GET s ; get another string
Clear Key
──────────────────────────────────────────────────────────────────────────
Function Clears the keyboard buffer and gives up keyboard control
after a INPUT or INPUTCH statement.
Syntax CLEAR KEY
Remark CLEAR KEY clears the content of the keyboard buffer. Keyboard
input before this statement are thrown away.
When the INPUT or INPUTCH statement in the script is
executed, the following input characters are placed in a
keyboard buffer no matter if we want to read the next key
or not. As a result, the following characters are NOT sent to
the remote system automatically. It is important to give up
the control of keyboard whenever no more keyboard input is
needed and the clear key statement is built for this purpose.
See also Input, InputCh
Example
PRINT "Input filename:"
INPUT filename ; ask the user to input a filename
CLEAR KEY ; give up keyboard control such that
; following keys are sent to remote
; system automatically
Clear Text
──────────────────────────────────────────────────────────────────────────
Function Clears the terminal window.
Syntax CLEAR TEXT
Remark CLEAR TEXT clears the terminal window and positions the
cursor to the upper-left corner. It sets the display
attribute to the initial setup.
TELEMATE SCRIPT BUILT IN PROCEDURES 26
Close
──────────────────────────────────────────────────────────────────────────
Function Closes a file.
Syntax CLOSE
Return Upon successful completion, SUCCESS is set to TRUE;
otherwise, SUCCESS is FALSE.
See also Open, Read, Write
ComInCount
──────────────────────────────────────────────────────────────────────────
Function Gets the number of characters in the incoming COM buffer.
Syntax COMINCOUNT count
Remark Telemate has an incoming COM buffer of 8000 bytes.
Return <count> contains the number of characters in the incoming COM
buffer.
See also Clear COM
ComOutCount
──────────────────────────────────────────────────────────────────────────
Function Gets the number of characters in the outgoing COM buffer.
Syntax COMOUTCOUNT count
Remark Telemate has an outgoing COM buffer of 2000 bytes.
Return <count> contains the number of characters in the outgoing COM
buffer.
See also Clear COM
Concat
──────────────────────────────────────────────────────────────────────────
Function Appends one string to another
Syntax CONCAT dest,src
Remark CONCAT appends a copy of <src> to the end of the string
<dest>.
If the backspace character "^H" is encountered in <src>, the
last character of the concatenating string is erased.
TELEMATE SCRIPT BUILT IN PROCEDURES 27
Return <dest> contains the concatenated string.
See also Length, StrDel, StrIns
Example
s = "abc" ; s = "abc"
CONCAT s,"xyz" ; s = "abcxyz"
CONCAT s,"^H" ; s = "abcxy"
CONCAT s,"pq" ; s = "abcxypq"
Create
──────────────────────────────────────────────────────────────────────────
Function Creates a new text file or rewrites an existing one.
Syntax CREATE filename
Remark CREATE creates the new text file <filename>. If the file
already exists, the old file is deleted.
Return Upon successful completion, SUCCESS is set to TRUE;
otherwise, SUCCESS is FALSE.
See also Append, Open
Date
──────────────────────────────────────────────────────────────────────────
Function Gets system date.
Syntax DATE today
Remark DATE fills the string <today> with the current date.
Dates can be compared with the usual '<', '>' and '='
relational operator.
The date format option in the main program does not affect
the format in the script language.
Return <today> contains the system current date in MM-DD-YY
format.
See also Time, ConvertDate
Example
DATE today
IF today>="01-01-91" AND today<"01-05-91"
PRINT "Happy New Year!"
ENDIF
TELEMATE SCRIPT BUILT IN PROCEDURES 28
Delay
──────────────────────────────────────────────────────────────────────────
Function Suspends script execution for an interval.
Syntax DELAY t
Remark With a call to DELAY, the script program is suspended from
execution for the number of tenth seconds specified by <t>.
Example
DELAY 15 ; wait for one and a half second
Delete
──────────────────────────────────────────────────────────────────────────
Function Deletes one or more files
Syntax DELETE filename
Remark DELETE deletes one or more files specified by <filename>.
Wildcards are allowed in <filename>.
Return On successful completion, SUCCESS is set to TRUE;
otherwise, SUCCESS is FALSE.
See also FileExist, Rename
Dial
──────────────────────────────────────────────────────────────────────────
Function Dials a list of entries or redials the current list.
Syntax DIAL
DIAL list
Remark DIAL redials the the current list of entries. If <list> is
specified, the current list is replaced by <list> and start
dialing.
The <DialAttempt> option is the maximum of number of dialing
attempt.
The <DialList> option can be used to specify the current dial
list.
Return DIAL sets CONNECTED to the number of the connected entry. If
the operator press [Esc] to abort the dialing process or the
attempts excess the <DialAttempt> option, CONNECTED is set to
0 (FALSE).
TELEMATE SCRIPT BUILT IN PROCEDURES 29
See also Set AutoRedial, Set DialAttempt, Set DialList, Set DialPause,
Set DialTime, Set MultiLine
Example
SET DialAttempt,3 ; try each entry once
SET DialList,"1 3 6" ; set the dial list
DIAL ; equivalent to a DIAL "1 3 6" statement
IF NOT CONNECTED
PRINT "All boards are busy."
ELSE
SWITCH CONNECTED
CASE 1: PRINT "connected to #1"
CASE 3: PRINT "connected to #3"
CASE 6: PRINT "connected to #6"
ENDSWITCH
ENDIF
SET DialAttempt,0 ; unlimit the maximum attempt
Dos
──────────────────────────────────────────────────────────────────────────
Function Jumps to DOS or issues a DOS command.
Syntax DOS
DOS command
Remark The DOS statement invokes the DOS COMMAND.COM file to execute
a DOS command, batch file, or other program named by the
string <command>. the program must be in the current
directory or in one of the directories listed in the PATH
environment string.
If <command> is not specified, the DOS statement jumps to DOS
and return when users enter 'EXIT' in the DOS command line.
If the <SwapToEms> or the <SwapToDisk> option is turned on,
Telemate swaps part of itself to second storage and, hence,
leaves more memory space for the DOS shell.
The COMSPEC envirnoment string is used to find the
COMMAND.COM file. If your COMMAND.COM is not in the root
directory - suppose in the C:\DOS directory, you should
include the following in the AUTOEXEC.BAT startup file.
SET COMSPEC=C:\DOS\COMMAND.COM
TELEMATE SCRIPT BUILT IN PROCEDURES 30
See also Set SwapToDisk, Set SwapToEms, Set MaxDosShell
Example
QUERY SwapToEms,ems ; store the original options
QUERY SwapToDisk,disk
QUERY MaxDosShell,max
SET SwapToEms,on ; provide more working space
SET SwapToDisk,on ; for external program
SET MaxDosShell,off ;
DOS "TMSTAT TM.USE" ; run the TMSTAT.EXE program
SET SwapToEms,ems
SET SwapToDisk,disk ; restore the original options.
SET MaxDosShell,max
ExitTelemate
──────────────────────────────────────────────────────────────────────────
Function Terminates Telemate's execution.
Syntax EXITTELEMATE
EXITTELEMATE exitCode
Remark EXITTELEMATE terminates Telemate and return to DOS. The file
in the Edit window is saved automatically if necessary.
If <exitCode> is not specified, Telemate exits to DOS with
the error level 0. Otherwise, the error level is set to
<exitCode>. Typically a value of 0 is used to indicate a
normal exit, and a nonzero value indicates some errors.
FileExist
──────────────────────────────────────────────────────────────────────────
Function Determines if a file or directory is exist.
Syntax FILEEXIST filename,existFlag
Remark FILEEXIST checks the file named by <filename> to determines
if it is exists.
Wildcards are allowed in <filename>.
Return If the file is exist, <existFlag> is set to TRUE; otherwise,
<existFlag> is FALSE.
See also Delete, Rename
FileSize
──────────────────────────────────────────────────────────────────────────
Function Gets file size in bytes.
Syntax FILESIZE filename,size
TELEMATE SCRIPT BUILT IN PROCEDURES 31
Remark FILESIZE returns the length, in bytes, of the file
specified by <filename>.
Return If <filename> exist, <size> is set to the file size and
SUCCESS is set to TRUE; otherwise, SUCCESS is set to FALSE.
See also Read, Seek
Get
──────────────────────────────────────────────────────────────────────────
Function Gets a string from remote system.
Syntax GET s
Remark GET collects a string, terminated by a carriage return, from
the remote system.
GET does not eliminate the BackSpace character [Ctrl H] from
the input, therefore a CONCAT statement should be perform
after the GET statement to eliminate the BackSpace character.
Return <s> contains the collected string. The ending carriage return
is discarded.
See also Clear COM, ComInCount, GetCh
Example
GET s ; get a string from remote system
filename = "" ; prepare the variable
CONCAT filename,s ; eliminate the BackSpace
GetCh
──────────────────────────────────────────────────────────────────────────
Function Gets a character from remote system.
Syntax GETCH ch
Remark GETCH gets a single character from the remote system. If no
character is available, GETCH return immediately. GETCH
statement, like the INKEY$ function in BASIC, does not wait.
Return If a character is successfully read into <ch>, SUCCESS is set
to TRUE; otherwise, SUCCESS is set to FALSE.
See also Get
TELEMATE SCRIPT BUILT IN PROCEDURES 32
Example
REPEAT ; to wait for a character,
GETCH ch ; repeat the GETCH until
UNTIL SUCCESS ; a character is available
HangUp
──────────────────────────────────────────────────────────────────────────
Function HangUps the modem.
Syntax HANGUP
Remark HANGUP sends the modem hangup string to modem. If the hangup
string is the "^#" macro sequence, Telemate hangs up the
modem by dropping DTR.
Image
──────────────────────────────────────────────────────────────────────────
Function Captures the terminal screen into an image file.
Syntax IMAGE
IMAGE filename
Remark IMAGE captures the terminal screen into an image file by
appending the screen to the file <filename>. If no <filename>
is supplied, the last image filename is used.
Input
──────────────────────────────────────────────────────────────────────────
Function Reads a string from the keyboard.
Syntax INPUT s
Remark INPUT collects a string, terminated by a [Enter],
from the keyboard.
When the INPUT statement in the script is executed, the
following input characters are placed in a keyboard buffer
no matter if they are to be read or not. As a result, they
NOT sent to the remote system automatically. It is important
to give up the control of keyboard whenever no more keyboard
input is needed using the CLEAR KEY statement.
INPUT does not eliminate the BackSpace character [Ctrl H]
from the input, therefore a CONCAT statement should be
perform after the INPUT statement to elimate the BackSpace
character.
Return <s> contains the collected string. The ending [Enter] is
discarded.
TELEMATE SCRIPT BUILT IN PROCEDURES 33
See also Clear Key, InputCh
Example
INPUT s ; get a string from remote system
filename = "" ; prepare the variable
CONCAT filename,s ; eliminate the BackSpace
CLEAR KEY ; give up keyboard control such that
; following keys are sent to remote
; system automatically
InputCh
──────────────────────────────────────────────────────────────────────────
Function Reads a character from the keyboard.
Syntax INPUTCH ch
Remark INPUTCH gets a single character from the keyboard. If no
character is available, INPUTCH returns immediately.
INPUTCH statement, like the INKEY$ function in BASIC, does
not wait.
When the INPUTCH statement in the script is executed, the
following input characters are placed in a keyboard buffer no
matter if they are to be read or not. As a result, they are
NOT sent to the remote system automatically. It is important
to give up the control of keyboard whenever no more keyboard
input is needed using the CLEAR KEY statement.
Return If a character is successfully read into <ch>, SUCCESS is set
to TRUE; otherwise, SUCCESS is set to FALSE.
See also Clear Key, Input
Example
REPEAT ; to wait for a character,
INPUTCH ch ; repeat the INPUTCH until
UNTIL SUCCESS ; a character is available
CLEAR KEY ; give up keyboard control such that
; following keys are sent to remote
; system automatically
Itoa
──────────────────────────────────────────────────────────────────────────
Function Converts an integer to a string.
Syntax ITOA i,s
Remark ITOA converts the integer <i> to a string and store it into
<s>.
TELEMATE SCRIPT BUILT IN PROCEDURES 34
Return <s> contains the string representation of the value <i>.
See also Atoi
Keystroke
──────────────────────────────────────────────────────────────────────────
Function Simulates keystrokes.
Syntax KEYSTROKE s
Remark KEYSTROKES simulates keystrokes as if they are generated by
the keyboard, including [Alt] keys. It is equivalent to the
'^-' keystroke simulation macro, except that the string <s>
does not include the '^-' symbol.
Example
KEYSTROKE "`1200`2e00`1400`1900"
; generates [Alt E] [Alt C] [Alt T] [Alt P] which switch to the
; editor, copy the marked text to the clipboard, switch to the
; terminal and paste the content in the clipboard to the remote
; system.
Length
──────────────────────────────────────────────────────────────────────────
Function Calculates the length of a string.
Syntax LENGTH s,len
Return <len> is the length of <s>. If <s> is an empty, <len>
is 0.
LoadFon
──────────────────────────────────────────────────────────────────────────
Function Loads a phone directory.
Syntax LOADFON phoneDir
Remark LOADFON loads the <phoneDir> with extension .FON and the
corresponding memo file .MEM into the dial window.
If <phoneDir> does not include a directory, the Telemate
directory is used. The extension .FON can be omitted.
Return Upon successful completion, SUCCESS is set to TRUE; if
<phoneDir> does not exist, SUCCESS is FALSE.
TELEMATE SCRIPT BUILT IN PROCEDURES 35
See also Dial
Example
LOADFON "LONGDIST.FON"
LoadKey
──────────────────────────────────────────────────────────────────────────
Function Loads a keyboard definition table.
Syntax LOADKEY keyTable
Remark LOADKEY loads the <keyTable> with extension .KEY.
If <keyTable> does not include a directory, the Telemate
directory is used. The extension .KEY can be omitted.
Return Upon successful completion, SUCCESS is set to TRUE; if
<keyTable> does not exist, SUCCESS is FALSE.
Example
LOADKEY "EUROPE.KEY"
LoadMac
──────────────────────────────────────────────────────────────────────────
Function Loads a macro definition table.
Syntax LOADMAC macroTable
Remark LOADMAC loads the <macroTable>, with extension .MAC into
the macro window.
If <macroTable> does not include a directory, the Telemate
directory is used. The extension .MAC can be omitted.
Return Upon successful completion, SUCCESS is set to TRUE; if
<macroTable> does not exist, SUCCESS is FALSE.
Example
LOADMAC "CIS.MAC"
LoadPad
──────────────────────────────────────────────────────────────────────────
Function Loads a keypad definition table.
Syntax LOADPAD keypadTable
TELEMATE SCRIPT BUILT IN PROCEDURES 36
Remark LOADPAD loads the <keypadTable>, with extension .PAD into the
macro window.
If <keypadTable> does not include a directory, the Telemate
directory is used. The extension .PAD can be omitted.
Return Upon successful completion, SUCCESS is set to TRUE; if
<keypadTable> does not exist, SUCCESS is FALSE.
Example
LOADPAD "VT102DEL.PAD"
LogOff
──────────────────────────────────────────────────────────────────────────
Function Closes the log file.
Syntax LOGOFF
Remark LOGOFF closes a previous opened log file.
Return LOGGING is set to 0 (FALSE).
See also LogOn, LogPause, LogResume
LogOn
──────────────────────────────────────────────────────────────────────────
Function Opens a log file and captures incoming data into the file.
Syntax LOGON
LOGON filename
Remark LOGON opens the log file <filename> and starts capturing the
incoming data into it.
If <filename> is not supplied, the filename specified in the
last LOGON statement is used. If there is no prevous LOGON
statement, the one in the log file field of the phone
directory is used. If this field is empty, "TM.LOG" is used.
Return Upon successful completion, SUCCESS is set to TRUE and
LOGGING is set to 1 (TRUE); otherwise, SUCCESS is 0 (FALSE).
See also LogOff, LogPause, LogResume
LogPause
──────────────────────────────────────────────────────────────────────────
Function Pauses capturing incoming data into the log file.
Syntax LOGPAUSE
TELEMATE SCRIPT BUILT IN PROCEDURES 37
Remark LOGPAUSE pauses capturing incoming data. The LOGGING variable
should be checked to determine if a log file open. A value of
1 indicates a log file is open.
Return LOGGING is set to 2.
See also LogOff, LogOn, LogResume
LogResume
──────────────────────────────────────────────────────────────────────────
Function Resumes capturing incoming data into the log file.
Syntax LOGRESUME
Remark LOGRESUME resumes capturing incoming data. The LOGGING
variable should be checked to determine if the log file is in
pause. A value of 2 indicates the log file is in pause.
Return LOGGING is set to 1.
See also LogOff, LogOn, LogPause
Open
──────────────────────────────────────────────────────────────────────────
Function Opens a text file for reading or writing.
Syntax OPEN filename
Remark OPEN opens the text file <filename> for reading and writing
and strip the ending EOF [Ctrl Z].
OPEN closes the previously open file automatically if no
CLOSE command is issued to that file.
Return Upon successful completion, SUCCESS is set to TRUE. If
<filename> does not exist, SUCCESS is FALSE.
See also Append, Close, Create, FileExist, FileSize, Read, Seek, Tell,
Write
Example
OPEN "MYFILE" ; open the file "MYFILE"
IF NOT SUCCESS ; report if not found
PRINT "File not found."
STOP
ENDIF
READ s ; read the first line
PRINT s ; print it
CLOSE ; close the file
TELEMATE SCRIPT BUILT IN PROCEDURES 38
OPEN "FILE1" ; open FILE1
OPEN "FILE2" ; close FILE1 and open FILE2
Print
──────────────────────────────────────────────────────────────────────────
Function Prints integers or strings to the terminal screen.
Syntax PRINT
PRINT s
PRINT i
PRINT s1,s2,i1,i2,s3, ...
PRINT s1,s2,i1,i2,s3, ... ,
Remark PRINT outputs variables or constants of integer or string to
the terminal screen. Each two arguments are separated by a
comma.
PRINT supplies a newline by default. If a comma follows, no
newline is supplied.
See also At, WhereX, WhereY
Example
PRINT "hello, world" ; say hello to everyone
PRINT "hello, ", ; say that again
PRINT "world",
PRINT
PRINT "x = ",x ; output multiple strings or integers
PRINT "My name is ",firstName," ",lastName
Put
──────────────────────────────────────────────────────────────────────────
Function Sends strings or integers to the remote system.
Syntax PUT
PUT s
PUT i
PUT s1,s2,i1,i2,s3, ...
PUT s1,s2,i1,i2,s3, ... ,
Remark Like the PRINT statement, PUT sends variables or constants of
types integer or string to the remote system. Each two
arguments are separated by a comma. Integers are converted to
their string representation automatically before transmitting
to the remote system.
PUT supplies a carriage return [Ctrl M] by default. If a
comma follows, no carriage return is supplied.
TELEMATE SCRIPT BUILT IN PROCEDURES 39
Control characters can be sent by using the '^' prefix. For
example, "^C" represents the [Ctrl C], "^M" the carriage
return [Enter] and "^[" the Escape key [Esc].
The following macro sequences have special meanings.
^^ the character '^'
^~ the character '~'
~ pause 0.5 second
^# drop DTR signal to hangup modem
^% break signal
^$ memo field in phone directory
^& password field in phone directory
^* modem hangup string
^( modem init string
^) modem answer string
See also Clear COM, ComOutCount, Waitfor
Example
PUT "first last" ; transmit first name and last name
; then a carriage return (^M)
PUT "first ", ; same as above
PUT "last",
PUT
PUT ; these two lines are
PUT "^M", ; equivalent
firstName = "first" ; set first and last name
lastName = "last"
password = "^&" ; use the password field in TM.FON
PUT firstName," ",lastName,"^M~~~~",password
; send name, [Enter], wait for 2 seconds then send
; the password, [Enter]
PUT "~^#~~^)", ; wait 0.5 second, drop DTR,
; wait 1 second, then sends the
; modem answer string
Query
──────────────────────────────────────────────────────────────────────────
Function Queries option value.
Syntax QUERY <OPTION>,<VALUE>
Remark The QUERY statement gives you the ability to peek most of the
system options.
All the options that the SET command accept can be queried by
the QUERY command. The returning value is the same as that in
TELEMATE SCRIPT BUILT IN PROCEDURES 40
the SET command. In addition, the following options are
accepted by the QUERY command:
<OPTION> <VALUE> Description
───────────── ──────── ──────────────────────────────────
Board "..." return the board name of the
connected entry
Phone "..." return the phone number of the
connected entry
Password "..." return the password of the
connected entry
Total nnn return the total number of
connection of the connected entry
LastCall "MM-DD-YY" return the date of the connected
entry
Memo "..." return the memo of the connected
entry
This command should be used to store the value of an option
before modifying the option and then restore the option to
its original before the execution stops.
See also Set
Example
QUERY zAutoDownload,autoZmodem
SET zAutoDownload,off
RECEIVE "z"
SET zAutoDownload,autoZmodem
QUERY board,bbs
QUERY password,pw
QUERY memo,mm
PRINT "#",CONNECTED," ",bbs," ",pw," ",mm
QUERY diallist,list
PRINT list
QUERY connection,conn
SWITCH conn
CASE 0: PRINT "Modem"
CASE 1: PRINT "Computer"
CASE 2: PRINT "Fossil"
CASE 3: PRINT "BIOS"
ENDSWITCH
QUERY parity,par
SWITCH par
CASE 0: PRINT "None"
CASE 1: PRINT "Odd"
CASE 2: PRINT "Even"
CASE 3: PRINT "Space"
CASE 4: PRINT "Mark"
ENDSWITCH
TELEMATE SCRIPT BUILT IN PROCEDURES 41
QUERY terminal,term
SWITCH term
CASE 0: PRINT "TTY"
CASE 1: PRINT "ANSI"
CASE 2: PRINT "VT52"
CASE 3: PRINT "VT102"
CASE 4: PRINT "AVATAR"
CASE 5: PRINT "PRISM"
ENDSWITCH
Read
──────────────────────────────────────────────────────────────────────────
Function Reads a string from a text file.
Syntax READ s
Remark READ reads characters from the file into <s>.
READ does not place the newline sequence CR-LF into the
string.
Return On success, <s> contains the string read and SUCCESS is set
to TRUE. SUCCESS is FALSE on end-of-file or error.
See also Close, Open, ReadCh, Seek, Tell
Example
OPEN "MYFILE" ; count lines in the file MYFILE
IF NOT SUCCESS
PRINT "File not found."
STOP ; stop if file not found
ENDIF
n = 0 ; number of line = 0
READ str ; read a line
WHILE SUCCESS ; repeat until end of file
n = n + 1 ; increase counter
READ str ; read the next string
ENDWHILE
CLOSE ; close the file
PRINT "There are ",n," lines in the file"
OPEN "TM.FON" ; read a record from the phone directory
recno = 10 ; read the record #10
reclen = 131 ; record length of a entry
SEEK recno*reclen ; seek to the record position
READ record ; read the record
CLOSE
TELEMATE SCRIPT BUILT IN PROCEDURES 42
ReadCh
──────────────────────────────────────────────────────────────────────────
Function Reads a character from a text file.
Syntax READCH ch
Remark READCH reads a single character from the file into <ch>.
In a text file, a CR [Ctrl M] followed by a LF [Ctrl J]
indicates end-of-line.
Return On success, <ch> contains the character read and SUCCESS is
set to TRUE. SUCCESS is FALSE on end-of-file or error.
See also Close, Open, ReadCh, Seek, Tell
Receive
──────────────────────────────────────────────────────────────────────────
Function Receives (Downloads) one or more files from the remote
system.
Syntax RECEIVE protocol
RECEIVE protocol,filename
Remark RECEIVE receives (download) one or more files from the remote
system using the protocol <protocol>. <protocol> can be one
of the following or the menu key for external protocol.
<protocol> Protocol <filename> needed
────────── ──────── ─────────────────
"Z" Zmodem No
"Y" Ymodem No
"G" Ymodem-G No
"B" Batch Ymodem No
"X" Xmodem Yes
"O" Xmodem-1K Yes
"R" Relaxed Xmodem Yes
"T" Telink No
"S" SEAlink No
"M" Modem7 No
"K" Kermit No
"C" CIS Quick B No
"A" ASCII Yes
For protocols, such as Xmodem, which does not pass the name,
<filename> should contains the name being received. Wildcards
are not allowed. If <filename> is "" and <GuessFile> option
is on, the guessing name is used.
TELEMATE SCRIPT BUILT IN PROCEDURES 43
Zmodem has the ability to start automatically which is called
Zmodem AutoDownload - the <zAutoDownload> option. To prevent
the download starts before the command RECEIVE "Z" is issued,
the <zAutoDownload> option should be turned off before
telling the remote system to start the transfer.
Return If the file transfer is successful, SUCCESS is set to TRUE;
SUCCESS is FALSE if the transfer abort.
For external protocols, SUCCESS is always set to TRUE.
See also Send, Set GuessFile, Set zAutoDownload, Waitfor
Example
RECEIVE "x","file.zip" ; Xmodem needs the filename
RECEIVE "y" ; Ymodem doesn't
RECIEVE "x","" ; use the guessing name as filename
QUERY zAutoDownload,auto ; store the auto download option
SET zAutoDownload,off ; you must turn it off before you tell
WAITFOR "command",10 ; the remote system to send the files,
PUT "d z *.zip" ; otherwise, the system's AutoDownload
RECEIVE "z" ; procedure will take the control and
; the RECEIVE command will return a
; wrong SUCCESS value, after the
SET zAutoDownload,auto ; transfer, you may restore it
IF SUCCESS
PRINT "File received successfully"
ELSE
PRINT "File transfer aborted"
ENDIF
Rename
──────────────────────────────────────────────────────────────────────────
Function Renames a file.
Syntax RENAME oldname,newname
Remark RENAME changes the name of a file from <oldname> to
<newname>.
Directories in <oldname> and <newname> need not be the same,
therefore, RENAME can be used to move a file from one
directory to another. Wildcards are not allowed.
Return On successfully renameing the file, SUCCESS is set to TRUE;
otherwise, SUCCESS is FALSE.
See also Delete, FileExist
TELEMATE SCRIPT BUILT IN PROCEDURES 44
Script
──────────────────────────────────────────────────────────────────────────
Function Executes another script program.
Syntax SCRIPT scriptName
Remark SCRIPT terminates the execution of the current script and
executes the script program <scriptName>.
<scriptName> may not contain the extension part of a
filename. If <scriptName> does not include a path, the Script
directory is used.
Example
SCRIPT "HOST" ; executes the HOST.SCR in the Script directory
Seek
──────────────────────────────────────────────────────────────────────────
Function Repositions the file pointer.
Syntax SEEK filepos
Remark SEEK sets the file pointer to the new position <filepos>. At
the beginning of a file, the file pointer is 0.
If <filepos> is -1, the file pointer is moved to the end of
the file.
Return If the pointer is successfully moved, SUCCESS is set to TRUE;
otherwise, SUCCESS is FALSE.
See also Read, ReadCh, Tell, Write
Example